package com.company;

import java.io.*;
import java.util.Scanner;

public class _编辑功能 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的id：");
       String id = scanner.nextLine();
       File f = new File(id+".txt");
        RandomAccessFile raf = new RandomAccessFile(f,"r");
        byte[] b = new byte[1024];//货车搬家！
        int len =-1;
        while((len=raf.read(b))!=-1){
            System.out.println(new String(b,0,len));
        }
            System.out.println("是否要修改个人信息？（”是“或”否“）");
        String s1 = scanner.nextLine();
        if(s1.equals("否")){
            raf.close();
        }else if(s1.equals("是")){
            f.delete();
            raf.close();
            System.out.println("请重新输入您的信息");
            File fi = new File(id+".txt");
            fi.createNewFile();
            System.out.println("请输入您的身份:");
            String str1=scanner.nextLine();
            System.out.println("输入姓名:");
            String str2 =scanner.nextLine();
            System.out.println("输入性别:");
            String str3 =scanner.nextLine();
            System.out.println("输入班级:");
            String str4 =scanner.nextLine();
            System.out.println("输入用电量:");
            String str5 =scanner.nextLine();
            System.out.println("输入用水量:");
            String str6 =scanner.nextLine();
            //打印流，修改打印输出端。
            PrintStream ps = new PrintStream(new FileOutputStream(fi));  //打印流属于处理流、输出流！并不直接关于文件！
            ps.println(id);
            ps.println(str1);
            ps.println(str2);
            ps.println(str3);
            ps.println(str4);
            ps.println(str5);
            ps.println(str6);
            ps.flush();
            ps.close();
        }else{
            System.out.println("请输入规范答案！");
        }
    }

        }










